<template>
	<view class="content">
		<view class="list_box1">
			<view class="part2" v-if="orderDelites.indentType == 1 || orderDelites.indentType == 2">
				<view class="box_add">
					<view class="distance">
						<!-- <view v-if="orderDelites.distancess>1000">{{(Number(orderDelites.distancess) / 1000).toFixed(2)}}</view>
						<view v-else>{{Number(orderDelites.distancess?(orderDelites.distancess).toFixed(2):0)}}</view>
						<view class="a" v-if="orderDelites.distancess>1000">km</view>
						<view class="a" v-else>m</view> -->
						<view>{{orderDelites.distancess}}</view>
					</view>
					<view class="add_name" @click="goStart()">
						<view class="buy">
							<image src="../../../static/rider/icon-buy.png"></image>
						</view>
						<view class="sh_name">
							{{orderDelites.shipAddressDetail}}
							<image
								src="https://pt2.0.xianmxkj.com/file/uploadPath/2023/01/28/daf10b235582c81cae1ed1542ea34cc7.png"
								style="width:33rpx;height: 37rpx;"></image>
						</view>
						<view class="xs_add">
							{{orderDelites.shipAddress?orderDelites.shipAddress:''}}
						</view>
					</view>
				</view>
				<view class="jiantou">
					<image src="../../../static/rider/jiantou.png"></image>
					<view>{{orderDelites.distance}}</view>
				</view>
				<view class="box_add">
					<view class="distance">
						<!-- <view v-if="orderDelites.distance>1000">{{(Number(orderDelites.distance)/ 1000).toFixed(2)}}</view>
						<view v-else>{{Number(orderDelites.distance?(orderDelites.distance).toFixed(2):0)}}</view>
						<view class="a" v-if="orderDelites.distance>1000">km</view>
						<view class="a" v-else>m</view> -->
						<view>{{orderDelites.distancessd}}</view>
					</view>
					<view class="add_name" @click="goEnd()">
						<view class="send">
							<image src="../../../static/rider/icon-send.png"></image>
						</view>
						<view class="sh_name">{{orderDelites.deilveryAddressDetail}}({{orderDelites.deliveryAddress}})
							<image
								src="https://pt2.0.xianmxkj.com/file/uploadPath/2023/01/28/daf10b235582c81cae1ed1542ea34cc7.png"
								style="width:33rpx;height: 37rpx;"></image>
						</view>
					</view>
				</view>
			</view>
			<view class="part2" v-if="orderDelites.indentType == 3 && orderDelites.buyType==0">
				<view class="box_add">
					<view class="distance">
						<!-- <view v-if="orderDelites.distance>1000">{{(Number(orderDelites.distance)/ 1000).toFixed(2)}}</view>
						<view v-else>{{Number(orderDelites.distance?(orderDelites.distance).toFixed(2):0)}}</view>
						<view class="a" v-if="orderDelites.distance>1000">km</view>
						<view class="a" v-else>m</view> -->
						<view>{{orderDelites.distancessd}}</view>
					</view>
					<view class="add_name" @click="goEnd()">
						<view class="send">
							<image src="../../../static/rider/icon-send.png"></image>
						</view>
						<view class="sh_name">{{orderDelites.deilveryAddressDetail}}({{orderDelites.deliveryAddress}})
							<image
								src="https://pt2.0.xianmxkj.com/file/uploadPath/2023/01/28/facf54f8f15002dbe2344f3197ccc455.png"
								style="width: 35rpx;height: 38rpx;"></image>
						</view>
					</view>
				</view>
			</view>
			<view class="part2" v-if="orderDelites.indentType == 3 && orderDelites.buyType==1">
				<view class="box_add">
					<view class="distance">
						<!-- <view v-if="orderDelites.distancess>1000">{{(Number(orderDelites.distancess) / 1000).toFixed(2)}}</view>
						<view v-else>{{Number(orderDelites.distancess?(orderDelites.distancess).toFixed(2):0)}}</view>
						<view class="a" v-if="orderDelites.distancess>1000">km</view>
						<view class="a" v-else>m</view> -->
						<view>{{orderDelites.distancess}}</view>
					</view>
					<view class="add_name" @click="goStart()">
						<view class="buy">
							<image src="../../../static/rider/icon-buy.png"></image>
						</view>
						<view class="sh_name">
							{{orderDelites.shipAddressDetail}}
							<image
								src="https://pt2.0.xianmxkj.com/file/uploadPath/2023/01/28/facf54f8f15002dbe2344f3197ccc455.png"
								style="width: 35rpx;height: 38rpx;"></image>
						</view>
						<view class="xs_add">
							{{orderDelites.shipAddress?orderDelites.shipAddress:''}}
						</view>
					</view>
				</view>
				<view class="jiantou">
					<image src="../../../static/rider/jiantou.png"></image>
					<view>{{orderDelites.distance}}</view>
				</view>
				<view class="box_add">
					<view class="distance">
						<!-- <view v-if="orderDelites.distance>1000">{{(Number(orderDelites.distance)/ 1000).toFixed(2)}}</view>
						<view v-else>{{Number(item.distance?(item.distance).toFixed(2):0)}}</view>
						<view class="a" v-if="orderDelites.distance>1000">km</view>
						<view class="a" v-else>m</view> -->
						<view>{{orderDelites.distancessd}}</view>
					</view>
					<view class="add_name" @click="goEnd()">
						<view class="send">
							<image src="../../../static/rider/icon-send.png"></image>
						</view>
						<view class="sh_name">{{orderDelites.deilveryAddressDetail}}({{orderDelites.deliveryAddress}})
							<image
								src="https://pt2.0.xianmxkj.com/file/uploadPath/2023/01/28/facf54f8f15002dbe2344f3197ccc455.png"
								style="width: 35rpx;height: 38rpx;"></image>
						</view>
					</view>
				</view>
			</view>
			<view class="part2" v-if="orderDelites.indentType == 4">
				<view class="box_add">
					<view class="distance">
						<!-- <view v-if="orderDelites.distancessd>1000">{{(Number(orderDelites.distancessd)/ 1000).toFixed(2)}}</view>
						<view v-else>{{Number(orderDelites.distancessd?(orderDelites.distancessd).toFixed(2):0)}}</view>
						<view class="a" v-if="orderDelites.distancessd>1000">km</view>
						<view class="a" v-else>m</view> -->
						<view>{{orderDelites.distancessd}}</view>
					</view>
					<view class="add_name" @click="goEnd()">
						<view class="send">
							<image src="../../../static/rider/icon-send.png"></image>
						</view>
						<view class="sh_name">{{orderDelites.deilveryAddressDetail}}({{orderDelites.deliveryAddress}})
							<image
								src="https://pt2.0.xianmxkj.com/file/uploadPath/2023/01/28/facf54f8f15002dbe2344f3197ccc455.png"
								style="width: 35rpx;height: 38rpx;"></image>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- <view class="tips_box" v-if="orderDelites.indentCode && isQHM != '否' && orderDelites.indentState != 2">
			<view class="tip_content">取货码</view>
			<view class="tips_box_qhm">{{orderDelites.indentCode}}</view>
		</view> -->

		<!-- tip -->
		<view class="tip_box">
			<view class="tip_part1">
				<view class="tip_title" v-if="orderDelites.indentType == 1">帮送清单</view>
				<view class="tip_title" v-if="orderDelites.indentType == 2">帮取清单</view>
				<view class="tip_title" v-if="orderDelites.indentType == 3">帮买清单</view>
				<view class="tip_title" v-if="orderDelites.indentType == 4">服务内容</view>
				<view class="tip_rider" v-if="orderDelites.prepayMoney">
					用户预付:￥<text>{{orderDelites.prepayMoney}}</text>
				</view>

				<view class="box_two1" v-if="orderDelites.itemType">{{orderDelites.itemType}}</view>
				<view class="box_two1" v-if="orderDelites.itemValue">{{orderDelites.itemValue}}</view>
				<view class="box_two1" v-if="orderDelites.itemWeight">{{orderDelites.itemWeight}}</view>
			</view>
			<u-line color="#F2F2F2" />
			<view class="tip_content" v-if="orderDelites.indentType == 3">
				{{orderDelites.productDetails?orderDelites.productDetails:''}}
			</view>
			<view class="tip_content" v-if="orderDelites.indentType == 1 || orderDelites.indentType == 2">
				备注：{{orderDelites.remarks?orderDelites.remarks:''}}</view>
			<view class="tip_content" v-if="orderDelites.indentType == 4">
				{{orderDelites.serviceDetails?orderDelites.serviceDetails:''}}
			</view>
		</view>
		<!-- 订单信息 -->
		<view class="order_box">
			<view class="order_title">订单信息</view>
			<view class="order_list">
				<view class="order_name">订单号码</view>
				<view class="order_numbers" @click="copyOrder(orderDelites.indentNumber)">{{orderDelites.indentNumber}}
					<u-icon name="order"></u-icon>
				</view>
			</view>
			<view class="order_list">
				<view class="order_name">预约时间</view>
				<view class="order_numbers" v-if="orderDelites.indentType==3">
					{{orderDelites.sendOutTime?orderDelites.sendOutTime:''}}
				</view>
				<view class="order_numbers" v-if="orderDelites.indentType==1||orderDelites.indentType==2">
					{{orderDelites.sendOutTime?orderDelites.sendOutTime:''}}
				</view>
			</view>
			<!-- <view class="order_list">
				<view class="order_name">发票抬头</view>
				<view class="order_numbers">无(不需要发票)</view>
			</view> -->
		</view>
		<!-- 费用明细 -->
		<view class="order_box">
			<view class="order_title">费用明细</view>
			<view class="order_list">
				<view class="income_name">跑腿费</view>
				<view class="income_numbers">¥<text>{{orderDelites.errandMoney}}</text></view>
			</view>
			<view class="order_list" v-if="orderDelites.tip">
				<view class="income_name">小费奖励</view>
				<view class="income_numbers">¥<text>{{orderDelites.tip?orderDelites.tip:0}}</text></view>
			</view>
			<view class="order_list" v-if="orderDelites.prepayMoney">
				<view class="income_name">商品费用</view>
				<view class="income_numbers1">¥<text>{{orderDelites.prepayMoney}}</text></view>
			</view>
		</view>
		<!-- 接单按钮 -->
		<view class="tabbar_btn" v-if="orderDelites.indentState==2">
			<!-- FF7F00 -->
			<!-- <cu-progress class="progress" borderRadius="60px" :value="v3" backgroundColor="#FFFFFF" width="100vw"
				infoSize="30px" handleSize="50" handleBorderRadius="60" showInfo="false" strokeWidth="45"
				@change="change">
			</cu-progress> -->
			<view class="btn" @click="bindorder">
				接单
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				orderDelites: {},
				longitude: '', //骑手起点经度
				latitude: '', //骑手起点纬度
				qiJuli: '', //骑手距离
				dianJuli: '', //店家之间距离
				checkCertification: '',
				userId: '',
				v3: 0,
				isQHM: '否',
				jiedanIstrue: false
			}
		},
		onLoad(options) {
			console.log(options)

			this.indentNumber = options.id


			let latitude = this.$queue.getData('latitude');
			let longitude = this.$queue.getData('longitude');
			if (latitude && longitude) {
				this.longitude = longitude
				this.latitude = latitude
				this.taskData()
			}

			var that = this
			that.$Request.getT('/app/common/type/636').then(res => { //是否开启取货码	636
				if (res.code == 0) {
					if (res.data && res.data.value) {
						that.isQHM = res.data.value;
					}
				}
			})
			uni.getLocation({
				type: 'wgs84',
				success: function(res) {
					console.log('当前位置的经度：' + res.longitude);
					console.log('当前位置的纬度：' + res.latitude);
					that.longitude = res.longitude
					that.latitude = res.latitude
					that.taskData()
				},
				fail: function() {
					console.log('获取地址失败')
					uni.startLocationUpdate({
						type: 'gcj02', //gcj02  wgs84
						isHighAccuracy: true, //开启高精度定位(！！！必需)
						geocode: true,
						success: res => {
							uni.onLocationChange(function(res2) {
								console.log('实时纬度：' + res2.latitude);
								console.log('实时经度：' + res2.longitude);
								that.latitude = res2.latitude
								that.longitude = res2.longitude
								that.taskData()

							});
						},
						fail: err => {
							// clearInterval(this.ordertimer)
							console.error('开启小程序接收位置消息失败：', err)
						},
						complete: msg => {
							// clearInterval(this.ordertimer)
							console.log('调用开启小程序接收位置消息 API 完成')
						}
					});
				}
			});
			if (this.indentNumber) {
				that.taskData()
			}

			this.userId = that.$queue.getData("userId");
		},
		onShow() {
			this.checkCertification = this.$queue.getData("checkCertification");
		},
		methods: {
			change(e) {
				// console.log('滑动滑动滑动滑动：', e.value,!this.jiedanIstrue)
				// console.log(this.jiedanIstrue)
				if (!this.jiedanIstrue) {
					if (e.value > 90) {
						this.jiedanIstrue = true
						this.bindorder()
					}
				}
			},
			copyOrder(value) {
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: () => { //复制成功的回调函数
						uni.showToast({ //提示
							title: '复制成功'
						})
					}
				});
			},
			// 获取任务数据
			taskData() {
				this.$Request.postT('/app/indent/indentMessage', {
					indentNumber: this.indentNumber,
					ol: this.longitude,
					od: this.latitude
				}).then(res => {
					if (res.code == 0) {
						this.jiedanIstrue = false
						if (res.data.distancess > 1000) {
							res.data.distancess = Number((res.data.distancess / 1000)).toFixed(2) + "km"
						} else {
							if (res.data.distancess == 0) {
								res.data.distancess = "0m";
							} else {
								res.data.distancess = Number(res.data.distancess).toFixed(1) + "m";
							}
						}

						if (res.data.distance > 1000) {
							res.data.distance = Number((res.data.distance / 1000)).toFixed(2) + "km"
						} else {
							res.data
							if (res.data.distance == 0) {
								res.data.distance = "0m";
							} else {
								res.data.distance = Number(res.data.distance).toFixed(1) + "m";
							}
						}

						if (res.data.distancessd > 1000) {
							res.data.distancessd = Number((res.data.distancessd / 1000)).toFixed(2) + "km"
						} else {
							if (res.data.distancessd == 0) {
								res.data.distancessd = "0m";
							} else {
								res.data.distancessd = Number(res.data.distancessd).toFixed(1) + "m";
							}
						}

						this.orderDelites = res.data
					} else {
						console.log('失败：', res.data)
					}

				});
			},
			bindorder() {
				let that = this
				if (!that.userId) {
					uni.showModal({
						title: '提示',
						content: '请先登录后再接单',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/login/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return;
				}
				if (that.checkCertification == null) {
					uni.showModal({
						title: '提示',
						content: '请先实名认证后再接单',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/riderMy/approve/approve'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return;
				}
				if (that.checkCertification == 0) {
					uni.showToast({
						title: '实名认证审核中,无法接单',
						icon: 'none'
					});
					return;
				}
				if (that.checkCertification == 2) {
					uni.showToast({
						title: '实名认证未通过,无法接单',
						icon: 'none'
					});
					return;
				}
				that.$Request.postT('/app/indent/indentReceiving', {
					indentNumber: that.indentNumber
				}).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: "接单成功",
							duration: 1500,
							icon: "none"
						});
						setTimeout(function() {
							uni.redirectTo({
								url: '/pages/index/orderdetail/orderdetail?id=' + that
									.indentNumber
							})
						}, 1500)

					} else {
						console.log('失败：', res.data)
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 1500
						});
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/index/index'
							})
						}, 1500)
					}
				});

			},
			// 计算两点之间的距离
			jsjl(qj, qw, jj, jw) {
				this.$Request.postT('/app/indent/findNewIndent', {
					ol: qj,
					od: qw,
					dl: jj,
					dd: jw
				}).then(res => {
					// if(){

					// }
				});
			},
			goStart() {
				// let obj = {
				// 	name: this.orderDelites.shipAddressDetail,
				// 	lat: this.orderDelites.shipAddressLatitude,
				// 	long: this.orderDelites.shipAddressLongitude,
				// }
				// this.navgate(obj)
				let name = this.orderDelites.shipAddressDetail;
				let lat = this.orderDelites.shipAddressLatitude;
				let long = this.orderDelites.shipAddressLongitude;
				this.$queue.goOpenLocation(lat, long, name);
			},
			goEnd() {
				// let obj = {
				// 	name: this.orderDelites.deilveryAddressDetail,
				// 	lat: this.orderDelites.deliveryAddressLatitude,
				// 	long: this.orderDelites.deliveryAddressLongitude,
				// }
				// this.navgate(obj)
				let name = this.orderDelites.deilveryAddressDetail;
				let lat = this.orderDelites.deliveryAddressLatitude;
				let long = this.orderDelites.deliveryAddressLongitude;
				this.$queue.goOpenLocation(lat, long, name);
			},
			navgate(e) {
				let plugin = requirePlugin('routePlan');
				let key = this.$queue.getData('mapKey'); //使用在腾讯位置服务申请的key
				let referer = this.$queue.getData('mapName'); //调用插件的app的名称

				let endPoint = JSON.stringify({ //终点
					'name': e.name,
					'latitude': e.lat,
					'longitude': e.long
				});
				wx.navigateTo({
					url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
				});
			}
		}
	}
</script>

<style>
	body {
		background: #e7e7e7;
	}

	.content {
		width: 100%;
		margin-bottom: 159rpx;
	}

	.list_box1 {

		width: 90%;
		margin: 0 auto;
		/* height: 320rpx; */
		background: #FFFFFF;
		border-radius: 23rpx;
		/* box-shadow: 0rpx 5rpx 5rpx 0rpx rgba(198, 186, 181, 0.20); */
		margin-top: 20rpx;
	}

	.part2 {
		width: 90%;
		margin: 0 auto;
		padding: 25rpx 0;
	}

	.box_add {
		display: flex;

	}

	.box_two1 {
		background: #c4e2ff;
		color: #359CFF;
		/* width: 60px; */
		height: 45rpx;
		padding: 2rpx 14rpx;
		font-size: 22rpx;
		/* text-align: center; */
		line-height: 45rpx;
		border-radius: 5rpx;
		/* margin-top: 20rpx; */
		margin-left: 10rpx;
	}

	.distance {
		flex: 1;
		text-align: center;
		font-size: 28rpx;
	}

	.a {
		font-size: 16rpx;
	}

	.add_name {
		flex: 8;
		position: relative;
	}

	.buy {
		position: absolute;
		top: 6rpx;
	}

	.buy image {
		width: 30rpx;
		height: 30rpx;
	}

	.send {
		position: absolute;
		top: 6rpx;
	}

	.send image {
		width: 30rpx;
		height: 30rpx;
	}

	.sh_name {
		font-size: 28rpx;
		font-weight: bold;
		letter-spacing: 2rpx;
		text-indent: 38rpx;
	}

	.xs_add {
		color: #999999;
		font-size: 21rpx;
		margin-top: 10rpx;
	}

	.jiantou {
		margin-left: 23rpx;
		display: flex;
		/* justify-content: space-between; */
		align-items: center;
	}

	.jiantou image {
		width: 20rpx;
		height: 40rpx;
	}

	.jiantou>view {
		margin-left: 10rpx;
	}

	.part3 {
		width: 90%;
		margin: 0 auto;
		display: flex;
	}

	.three_left {
		flex: 1;
		height: 100rpx;
		display: flex;
		justify-content: left;
		align-items: center;
	}

	.three_left image {
		width: 36rpx;
		height: 37rpx;
	}

	.three_left text {
		color: #333333;
		font-size: 25rpx;
		margin-left: 10rpx;
	}

	.three_right {
		flex: 1;
		height: 100rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		color: #FF412D;
		font-size: 32rpx;
		font-weight: bold;
	}

	.tips_box {
		width: 90%;
		margin: 0 auto;
		background: #FFFFFF;
		margin-top: 20rpx;
		padding: 30rpx;
		border-radius: 22rpx;
		text-align: center;
	}
	
	.tips_box_qhm{
		color: #333333;
		font-size: 50rpx;
		font-weight: bold;
		height: 200rpx;
		line-height: 200rpx;
	}

	/* tip */
	.tip_box {
		width: 90%;
		margin: 0 auto;
		height: 180rpx;
		background: #FFFFFF;
		margin-top: 20rpx;
		border-radius: 22rpx;
	}

	.tip_part1 {
		display: flex;
		align-items: center;
	}

	.tip_title {
		/* flex: 1; */
		height: 80rpx;
		display: flex;
		justify-content: left;
		align-items: center;
		font-size: 26rpx;
		font-weight: bold;
		margin-left: 30rpx;
	}

	.tip_rider {
		/* flex: 1; */
		font-size: 20rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		margin-left: 30rpx;
	}

	.tip_rider text {
		font-size: 30rpx;
	}

	.tip_content {
		width: 90%;
		margin: 0 auto;
		font-size: 27rpx;
		font-weight: bold;
		letter-spacing: 2rpx;
		margin-top: 15rpx;
	}

	.u-line {
		border-bottom-width: 3px !important;
	}

	/* 订单信息 */
	.order_box {
		width: 90%;
		margin: 0 auto;
		/* height: 300rpx; */
		background: #ffffff;
		margin-top: 20rpx;
		border-radius: 22rpx;
	}

	.order_title {
		width: 90%;
		margin: 0 auto;
		font-size: 26rpx;
		font-weight: 600;
		line-height: 67rpx;
		letter-spacing: 3rpx;
	}

	.order_list {
		display: flex;
	}

	.order_name {
		flex: 1;
		margin-left: 35rpx;
		color: #999999;
		font-size: 25rpx;
		height: 75rpx;
		display: flex;
		justify-content: left;
		align-items: center;
	}

	.order_numbers {
		flex: 1;
		color: #333333;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		font-size: 22rpx;
		margin-right: 35rpx;
	}

	/* 费用明细 */
	.income_name {
		flex: 1;
		margin-left: 35rpx;
		color: #999999;
		font-size: 25rpx;
		height: 75rpx;
		display: flex;
		justify-content: left;
		align-items: center;
	}

	.income_numbers {
		flex: 1;
		color: #333333;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		font-size: 24rpx;
		margin-right: 35rpx;
	}

	.income_numbers1 {
		flex: 1;
		color: #FF2400;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		font-size: 24rpx;
		margin-right: 35rpx;
	}

	/* 接单按钮 */
	.tabbar_btn {
		position: fixed;
		bottom: 0rpx;
		left: 0rpx;
		right: 0rpx;
		width: 100%;
		height: 120rpx;
		background: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.btn {
		width: 90%;
		height: 80rpx;
		background: #FF7F00;
		border-radius: 21rpx;
		color: white;
		text-align: center;
		line-height: 80rpx;
		font-size: 26rpx;
	}

	.progress {
		margin: 5px 0;
	}
</style>